// axios.get('student/list').then((res) => {
//   console.log(res);
// });

// 点击a标签切换登录和注册
const registerBox = document.querySelector('.register');
const loginBox = document.querySelector('.login');
const registerA = document.querySelector('.register-a');
const loginA = document.querySelector('.login-a');

registerA.addEventListener('click', function () {
  loginBox.style.display = 'block';
  registerBox.style.display = 'none';
});
loginA.addEventListener('click', function () {
  loginBox.style.display = 'none';
  registerBox.style.display = 'block';
});
registerBox.querySelector('form').addEventListener('submit', function (e) {
  e.preventDefault();
  const data = $(this).serialize();
  axios.post('/api/register', data).then((res) => {
    if (res.data.code === 0) {
      toastr.success(res.data.message);
      registerA.click();
    } else {
      console.log(111);
      // toastr.error(res.data.messages);
    }
  });
});

// 登录功能
loginBox.querySelector('form').addEventListener('submit', function (e) {
  e.preventDefault();
  const data = $(this).serialize();
  axios.post('/api/login', data).then((res) => {
    console.log(res);
    if (res.data.code === 0) {
      toastr.success(res.data.message);
      localStorage.setItem('token', res.data.token);

      setTimeout(() => {
        location.href = 'index.html';
      }, 1000);
    }
  });
});
